package com.smartlbs.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smartlbs.baseframe.web.ResponseInfo;
import com.smartlbs.entity.SysUser;
import com.smartlbs.mapper.SysUserMapper;
import com.smartlbs.service.ISysUserService;
import com.smartlbs.util.MD5Util;
@Service
public class SysUserServiceImpl implements ISysUserService {
	@Autowired
	private SysUserMapper Mapper;
	@Override
	public SysUser login(String name, String password) {
		// TODO Auto-generated method stub
	
		
		SysUser user = new SysUser();
		user.setName(name);
		user.setPassword(MD5Util.getMD5Value(password));
		user.setLastLogin(new Date());
		SysUser login = Mapper.login(user);
		//更新登录时间
		if(login!=null){
			return login;
		}
		return null;
	}

	@Override
	public  ResponseInfo insert(String name, String password) {
		// TODO Auto-generated method stub
		ResponseInfo info = new ResponseInfo();
		info.setMessage("注册失败");
		//info.setSuccess(false);
		info.setResult(1);
		SysUser user = new SysUser();
		user.setName(name);
		user.setPassword(MD5Util.getMD5Value(password));
		user.setCreateTime(new Date());
		int insert = Mapper.insert(user);
		if(insert>0){
			info.setMessage("注册成功");
			//info.setSuccess(true);
			info.setResult(1);
		}
		return info;
	}

	@Override
	public int update(String name, String password) {
		// TODO Auto-generated method stub
		SysUser user = new SysUser();
		user.setName(name);
		user.setPassword(MD5Util.getMD5Value(password));
		int update = Mapper.update(user);
		return update;
	}

	@Override
	public int delete(long id) {
		// TODO Auto-generated method stub
		int delete = Mapper.delete(id);
		return delete;
	}

}
